export function promisifyApi(api, option) {
    return new Promise((resolve, reject) => {
        api({
            ...option,
            success(success) {
                resolve(success)
            },
            fail(fail) {
                reject(fail)
            }
        })
    })
}


export function debounce(func, wait) {
    let timer;
    return function () {
        let context = this;
        if (timer) {
            timer = clearTimeout(timer);
        }
        let args = arguments;
        timer = setTimeout(() => {
            func.apply(context, args)
        }, wait);
    }
}

export function throttle(func, wait) {
    let timeout;
    return function () {
        let context = this;
        let args = arguments;
        if (!timeout) {
            timeout = setTimeout(() => {
                timeout = null;
                func.apply(context, args)
            }, wait)
        }
    }
}